package io.sage.ch01.v4;

/**
 * 电影
 */
public class Movie {
    // 儿童片
    public static final int CHILDRENS = 2;
    // 普通片
    public static final int REGULAR = 0;
    // 新片
    public static final int NEW_RELEASE = 1;

    // 标题
    private String _title;
    // 价格
    private int _priceCode;

    public Movie(String _title, int _priceCode) {
        this._title = _title;
        this._priceCode = _priceCode;
    }

    public String getTitle() {
        return _title;
    }

    public int getPriceCode() {
        return _priceCode;
    }

    public void setPriceCode(int _priceCode) {
        this._priceCode = _priceCode;
    }

    /**
     * 最好不要在另一个对象的属性上运用switch语句，如果要用也在自己类的数据上使用。
     * 所以将getCharge从Rental类移至Movie类。
     *
     * @param daysRented
     * @return
     */
    public double getCharge(int daysRented) {
        double result = 0;
        switch (getPriceCode()) {
            case Movie.REGULAR:
                result += 2;
                if (daysRented > 2) {
                    result += (daysRented - 2) * 1.5;
                }
                break;
            case Movie.NEW_RELEASE:
                result += daysRented * 3;
                break;
            case Movie.CHILDRENS:
                result += 1.5;
                if (daysRented > 3) {
                    result += (daysRented - 3) * 1.5;
                }
                break;
            default:
        }
        return result;
    }

    /**
     * 类似getCharge的处理方法，将其从Rental类移至Movie类
     *
     * @param daysRented
     * @return
     */
    public int getFrequentRenterPoints(int daysRented) {
        if ((getPriceCode() == Movie.NEW_RELEASE) && daysRented > 1) {
            return 2;
        } else {
            return 1;
        }
    }
}
